﻿using MediatR;
using PersonalWebsite.Core.Result;

namespace PersonalWebsite.Core.CQRS;

internal interface IQueryHandler<TRequest, TResponse, TData> : IRequestHandler<TRequest, TResponse>
  where TRequest : IQuery<TResponse, TData>
  where TResponse : ApiResult<TData>
{
}

public abstract class QueryHandler<TRequest, TResponse, TData> : IQueryHandler<TRequest, TResponse, TData>
  where TRequest : IQuery<TResponse, TData>
  where TResponse : ApiResult<TData>
{
    private readonly IDBConnectionFactory _dBConnectionFactory;

    public QueryHandler(IDBConnectionFactory dBConnectionFactory)
    {
        _dBConnectionFactory = dBConnectionFactory;
    }

    public abstract Task<TResponse> Handle(TRequest request, CancellationToken cancellationToken);
}
